<?php


namespace app\admin\controller;


use app\admin\service\LoginService;
use app\common\Annotation\ControllerAnnotation;
use app\common\Annotation\NodeAnotation;
use app\common\controller\BackendController;
use think\captcha\Captcha;
use think\facade\Request;

/**
 * Class LoginController
 * @ControllerAnnotation(title="登陆",auth=0)
 * @package app\admin\controller
 */
class LoginController extends BackendController
{


    public function index()
    {
        if (Request::isAjax()) {
            $params = Request::param();
            $res = LoginService::login($params);
            if ($res) {
                return success_json_response("登陆成功");
            } else {
                return json_response("登陆失败");
            }
        } else {
            if (LoginService::isLogin()) {
                $this->redirect(url("index/index"));
            }
            return $this->fetch();
        }
    }

    /**
     * @NodeAnotation(title="退出登陆",auth=1)
     * @return mixed
     */
    public function login_out()
    {
        LoginService::login_out();
        return success_json_response("退出成功");
    }


    public function no_right()
    {
        return $this->fetch();
    }


    public function captcha()
    {
        $config = config("captcha.");
        $captcha = new Captcha($config);
        return $captcha->entry();
    }


}